'use strict';

/**
 * @ngdoc function
 * @name newWfApp.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the newWfApp
 */
angular.module('newWfApp')
        .controller('TaskListController', function ($scope, $http, $location) {
            $scope.sort = {
                orderBy: "iid",
                reverse: ""
            };
            $scope.openDetail = openDetail;
            $scope.toggleSorting = toggleSorting;

            $http.get('http://10.28.6.9:8080/NDK_WF_AL/task/getAutomaticTasks').then(function (response) {
                $scope.tasks = response.data.instance;
            });

            function openDetail(task) {
                $location.path('/tasks/' + task.iid);
            }
            function toggleSorting(column) {
                if ($scope.sort.orderBy !== column) {
                    $scope.sort.orderBy = column;
                } else {
                    $scope.sort.reverse = !$scope.sort.reverse;
                }
            }

        });

